package com.sise.controller;

import com.sise.bean.CodeMsg;
import com.sise.bean.ProductInfoBean;
import com.sise.entity.ProductInfo;
import com.sise.service.IProductInfoService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zj
 */
@RestController
@RequestMapping("/sise/product-info")
public class ProductInfoController {

    @Resource
    private IProductInfoService productInfoService;

    @RequestMapping("/findByStoreTransformation")
    public List<ProductInfoBean> findByStoreTransformation(Integer storeId) {
        return productInfoService.findByStoreTransformation(storeId);
    }

    @RequestMapping("/findByStoreId")
    public List<ProductInfo> findByStoreId(Integer storeId) {
        return productInfoService.findByStoreId(storeId);
    }

    @PostMapping("/deleteById")
    public CodeMsg deleteById(Integer id) {
        boolean isDelete = productInfoService.deleteById(id);
        if (isDelete) {
            return new CodeMsg().setCode(200).setMsg("删除成功！");
        }
        return new CodeMsg().setCode(400).setMsg("删除失败！");
    }

    @PostMapping("/updateById")
    public CodeMsg updateById(ProductInfo productInfo) {
        boolean isUpdate = productInfoService.updateById(productInfo);
        if (isUpdate) {
            return new CodeMsg().setCode(200).setMsg("修改成功！");
        }
        return new CodeMsg().setCode(400).setMsg("修改失败！");
    }

    @PostMapping("/addProductInfo")
    public CodeMsg addProductInfo(MultipartFile multipartPicture, ProductInfo productInfo) {
        return productInfoService.addProductInfo(multipartPicture, productInfo);
    }
}
